import request from '@/utils/request'
import qs from 'qs'

export function login(username, password, grant_type, client_id, client_secret) {
  return request({
    url: '/oauth/token',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: {
      username,
      password,
      grant_type,
      client_id,
      client_secret
    },
    transformRequest: [function(data) {
      // 将json转为form格式
      return qs.stringify(data)
    }]
  })
}

export function getTokenInfo() {
  return request({
    url: '/oauth/info',
    method: 'get'
  })
}

export function createAdmin(params) {
  return request({
    url: '/oauth/signup',
    method: 'post',
    data: params
  })
}

export function changePass(params) {
  return request({
    url: '/oauth/password',
    method: 'post',
    data: params
  })
}
